package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.OhFeiGoodsInfoDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.OhFeiGoodsInfo;

/**
 * 
 * @description 殴飞产品DAO
 * @author Wangxuegang
 * @date 2012-9-29
 * 
 */
@Repository("ohFeiGoodsInfoDAO")
public class OhFeiGoodsInfoDAOImpl extends SuperDAO<OhFeiGoodsInfo> implements
		OhFeiGoodsInfoDAO {

	/**
	 * 分页查询
	 * 
	 * @param ohFeiGoodsInfo
	 * @return
	 */
	@Override
	public Pagination<OhFeiGoodsInfo> queryPaginationList(
			OhFeiGoodsInfo ohFeiGoodsInfo) {
		Pagination<OhFeiGoodsInfo> paginationList = null;
		Integer rowCount = queryRowCount(ohFeiGoodsInfo);

		ohFeiGoodsInfo.calculate();
		List<OhFeiGoodsInfo> list = queryResultList(ohFeiGoodsInfo);

		paginationList = this.queryPagination(rowCount, list, ohFeiGoodsInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(OhFeiGoodsInfo ohFeiGoodsInfo) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.OhFeiGoodsInfoMapper.queryRowCount",
				ohFeiGoodsInfo);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param ohFeiGoodsInfo
	 * @return
	 */
	private List<OhFeiGoodsInfo> queryResultList(OhFeiGoodsInfo ohFeiGoodsInfo) {
		List<OhFeiGoodsInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.OhFeiGoodsInfoMapper.queryResultList",
				ohFeiGoodsInfo);
		return list;
	}

	/**
	 * 根据产品Id，查询单条记录
	 * 
	 * @param goodsId
	 * @return
	 */
	@Override
	public OhFeiGoodsInfo queryById(String goodsId) {
		OhFeiGoodsInfo ohFeiGoodsInfo = null;
		ohFeiGoodsInfo = this.getSqlSession().selectOne(
				"mybatis.xml.OhFeiGoodsInfoMapper.queryById", goodsId);

		return ohFeiGoodsInfo;
	}

	/**
	 * 记录更新
	 * 
	 * @param ohFeiGoodsInfo
	 * @return
	 */
	@Override
	public void update(OhFeiGoodsInfo ohFeiGoodsInfo) {
		this.getSqlSession().update("mybatis.xml.OhFeiGoodsInfoMapper.update",
				ohFeiGoodsInfo);
	}

	/**
	 * 殴飞产品新增
	 * 
	 * @param ohFeiGoodsInfo
	 * @date 2012-09-20
	 */
	@Override
	public void insert(OhFeiGoodsInfo ohFeiGoodsInfo) {
		this.getSqlSession().insert("mybatis.xml.OhFeiGoodsInfoMapper.insert",
				ohFeiGoodsInfo);
	}

	@Override
	public List<OhFeiGoodsInfo> queryAllGoodsInfo() {
		List<OhFeiGoodsInfo> list = this.getSqlSession().selectList(
				"mybatis.xml.OhFeiGoodsInfoMapper.queryAllGoodsInfo");
		return list;
	}

	@Override
	public void updateState(OhFeiGoodsInfo ohFeiGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.OhFeiGoodsInfoMapper.updateState", ohFeiGoodsInfo);
	}

}
